<template>
	<view>
		<view class="my-settle-container">
			<view class="radio" @click="clickFullCheck">
				<radio :checked ="isFullCheck" color="#C00000"/><text>全选</text>
			</view>
			
			<view class="amount-box">
				合计：<text class="amout">￥{{checkedGoodsAmount}}</text>
			</view>
			
			<view class="btn-settle" @click="settlement">
				结算({{checkedCount}})
			</view>
		</view>
	</view>
	
</template>

<script>
	import {mapGetters,mapMutations,mapState} from 'vuex'
	export default {
		name:"mysettle",
		data() {
			return {
				seconds:3,
				timer:null
			};
		},
		computed:{
			...mapGetters('m_cart',['checkedCount','total','checkedGoodsAmount']),
			...mapState('m_user',['token']),
			isFullCheck(){
				return this.total === this.checkedCount
			}
		},
		methods:{
			...mapMutations('m_cart',['updateAllGoodsState']),
			
			clickFullCheck(){
				// console.log('点击全选')
				this.updateAllGoodsState(!this.isFullCheck)
			},
			settlement(){
				if(!this.checkedCount) return this.$showMsg('请选择要结算的商品')
				if(!this.token) this.delayNavigate()
			},
			showtips(n){
				uni.showToast({
					icon:'none',
					title:'请登录后再结算！'+n+'秒后自动跳转到登录页',
					mask:true,//防止点击穿透
					duration:2500
				})
			},
			delayNavigate(){
				this.seconds=3
				this.showtips(this.seconds)
				
				this.timer = setInterval(()=>{
					this.seconds--
					if(this.seconds<=0){
						clearInterval(this.timer)
						uni.switchTab({
							url:'/pages/my/my'
						})
						return
					}
					this.showtips(this.seconds)
				},1000)
			}
			
		}
	}
</script>

<style lang="scss">
.my-settle-container{
	
	width: 100%;
	height: 50px;
	background-color: cyan;
	position: fixed;
	bottom: 50px;
	left: 0;
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 14px;
	padding-left: 5px;
	
	.radio{
		display: flex;
		align-items: center;
	}
	
	.amount-box{
		.amout{
			color: red;
			font-weight: bold;
		}
	}
	
	.btn-settle{
		background-color: #C00000;
		color: white;
		min-width: 100px;
		height: 50px;
		line-height: 50px;
		text-align: center;
		padding: 0 10px;
	}
	
}
</style>